package com.demo.controller;

import com.demo.constant.Constant;
import com.demo.pojo.UserInfo;
import com.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @author : liuf
 * @version V1.0
 * @title: LoginController
 * @date 2021年11月19日 16:42
 **/
@Controller
@RequestMapping("/login")
public class UserController {


    @Autowired
    private UserService userService;

    @RequestMapping("toLogin")
    public String toLogin() {
        System.out.println("================++++++++++++++跳转登录页面");
        return "login";
    }

    @PostMapping("/loginSystem")
    public String login(UserInfo loginUser, HttpSession session) {
        UserInfo userInfo = userService.loginCheck(loginUser);
        if (userInfo == null) {
            return "login";
        } else {
            session.setAttribute(Constant.LOGIN_USER, userInfo);
            return "redirect:/demo/result";
        }
    }
    
}
